package com.jianbo.proxy.util;

import java.util.LinkedHashMap;

import com.jianbo.proxy.conf.PropertiesConf;

public class ContentTypeUtil {
    
    static LinkedHashMap<String, String> map;

    static {
        String json = ResourceUtil.readString("contentType.json");
        map = JsonUtil.parseSortMap(json);
    }

    public static String contentType(String type) {
        String encoding = PropertiesConf.getInstance().getEncoding();
        if(encoding == null) {
            return map.get(type);    
        } else {
            return map.get(type) + ";charset=" + encoding;
        }
    }

    public static String contentTypeByPath(String path) {
        int pos = path.lastIndexOf(".");
        String type = path.substring(pos + 1);
        return contentType(type);
    }
}
